package com.yidu.t299.service.ljc.impl;
import com.yidu.t299.dao.ljc.MaterialMapper;
import com.yidu.t299.domain.ljc.Material;
import com.yidu.t299.service.ljc.MaterialBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 刘建常
 * @version 1.0
 * @description
 * @date:2023/3/7 12:19
 */
@Service
@Transactional
public class MaterialBizImpl implements MaterialBiz {
    @Autowired
    private MaterialMapper materialMapper;

    @Override
    public int deleteByPrimaryKey(Integer stockId) {
        return materialMapper.deleteByPrimaryKey(stockId);
    }

    @Override
    public int insert(Material record) {
        return materialMapper.insert(record);
    }

    @Override
    public Material selectByPrimaryKey(Integer stockId) {
        return materialMapper.selectByPrimaryKey(stockId);
    }

    public List<Material> selectByPage(int rows, int page, String condition) {
        return materialMapper.selectByPage(rows, page, condition);
    }

    @Override
    public int selectCount(String condition) {
        return materialMapper.selectCount(condition);
    }

    @Override
    public int updateByPrimaryKey(Material record) {
        return materialMapper.updateByPrimaryKey(record);
    }

    @Override
    public String getCondition(Material record) {
        // 定义条件字符串变量，初始值为空格字符串
        String condition = " ";
        // 如果校区对象为空，则直接返回空条件字符串
        if (record == null) {
            return condition;
        }
        // 如果校区编号不为空(如果是基本类型就直接判断!=0)
        if (record.getStockId() != null) {
            condition += " and stock_id = " + record.getStockId();
        }
        // 如果校区名称不为空
        if (record.getTextbookName() != null && record.getTextbookName().trim().length() != 0) {
            condition += " and textbook_name like '%" + record.getTextbookName() + "%'";
        }

        if (record.getTextbookNum() != null) {
            condition += " and textbook_num = " + record.getTextbookNum();
        }

        if (record.getTextbookAuthor() != null && record.getTextbookAuthor().trim().length() != 0) {
            condition += " and textbook_author like '%" + record.getTextbookAuthor() + "%'";
        }

        if (record.getTextbookPrice() != null && record.getTextbookPrice().trim().length() != 0) {
            condition += " and textbook_price = " + record.getTextbookPrice() + "%'";
        }

        // 返回条件字符串
        return condition;
    }
}
